package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/sensitive")
public class WmSensitiveController {
    @Autowired
    private WmSensitiveService wmSensitiveService;

    /**
     * 新增敏感词
     *
     * @param wmSensitive
     * @return
     */
    @PostMapping("/save")
    public ResponseResult add(@RequestBody WmSensitive wmSensitive) {

        wmSensitiveService.addSensitive(wmSensitive);
        //返回响应
        return ResponseResult.errorResult(200, "操作成功");
    }

    /**
     * 修改敏感词
     *
     * @param wmSensitive
     * @return
     */
    @PostMapping("/update")
    public ResponseResult updateSensitive(@RequestBody WmSensitive wmSensitive) {

        wmSensitiveService.updateSensitive(wmSensitive);
        //返回响应
        return ResponseResult.errorResult(200, "操作成功");
    }

    /**
     * 删除敏感词
     *
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult deleteSensitive(@PathVariable Integer id) {
        wmSensitiveService.deleteById(id);

        return ResponseResult.okResult(200, "删除成功");
    }

    /**
     * 敏感词分页
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult pageWmSensitive(@RequestBody SensitiveDto dto) {

        return wmSensitiveService.pageWmSensitive(dto);
    }
}
